<?php
namespace Admin\Models\ask;

use Admin\Models\BaseModel;
class XhaskOption extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iAOId;

    /**
     *
     * @var integer
     */
    public $iAQId;

    /**
     *
     * @var string
     */
    public $sOptionContent;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var integer
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var integer
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHAsk_Option");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHAsk_Option';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhaskOption[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhaskOption
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 根据题目id及选项内容创建新model并返回
     *
     * @param $questionId
     * @param $optionContent
     * @return XhaskOption
     *
     * create by ck 20160924
     */
    public static function createRecord($questionId, $optionContent)
    {
        $obj = new self;
        $obj->iAQId = $questionId;
        $obj->sOptionContent = $optionContent;
        return $obj;
    }

    /**
     * 根据题目ID数组获取选项信息
     *
     * @param array $queId
     *
     * create by ck 20160926
     */
    public static function getOptionsByQueIdArr($queId)
    {
        return self::find(array(
            'columns'       => 'iAOId,iAQId,sOptionContent',
            'conditions'    => 'bDelete=0 AND iAQId IN ({iAQIds:array})',
            'bind'          => array(
                'iAQIds'    => $queId
            )
        ))->toArray();
    }

}
